home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class PipedInputStream extends InputStream {
- boolean closed = true;
- Thread readSide;
- Thread writeSide;
- private byte[] buffer = new byte[1024];
- // $FF: renamed from: in int
- int field_0 = -1;
- int out;
-
- public PipedInputStream(PipedOutputStream var1) throws IOException {
- this.connect(var1);
- }
-
- public PipedInputStream() {
- }
-
- public void connect(PipedOutputStream var1) throws IOException {
- var1.connect(this);
- }
-
- synchronized void receive(int var1) throws IOException {
- this.writeSide = Thread.currentThread();
-
- while(this.field_0 == this.out) {
- if (this.readSide != null && !this.readSide.isAlive()) {
- throw new IOException("Pipe broken");
- }
-
- this.notifyAll();
-
- try {
- this.wait(1000L);
- } catch (InterruptedException var2) {
- throw new InterruptedIOException();
- }
- }
-
- if (this.field_0 < 0) {
- this.field_0 = 0;
- this.out = 0;
- }
-
- this.buffer[this.field_0++] = (byte)(var1 & 255);
- if (this.field_0 >= this.buffer.length) {
- this.field_0 = 0;
- }
-
- }
-
- synchronized void receive(byte[] var1, int var2, int var3) throws IOException {
- while(true) {
- --var3;
- if (var3 < 0) {
- return;
- }
-
- this.receive(var1[var2++]);
- }
- }
-
- synchronized void receivedLast() {
- this.closed = true;
- this.notifyAll();
- }
-
- public synchronized int read() throws IOException {
- int var1 = 2;
-
- while(this.field_0 < 0) {
- this.readSide = Thread.currentThread();
- if (this.writeSide != null && !this.writeSide.isAlive()) {
- --var1;
- if (var1 < 0) {
- throw new IOException("Pipe broken");
- }
- }
-
- if (this.closed) {
- return -1;
- }
-
- this.notifyAll();
-
- try {
- this.wait(1000L);
- } catch (InterruptedException var3) {
- throw new InterruptedIOException();
- }
- }
-
- int var2 = this.buffer[this.out++] & 255;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
-
- return var2;
- }
-
- public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
- if (var3 <= 0) {
- return 0;
- } else {
- int var4 = this.read();
- if (var4 < 0) {
- return -1;
- } else {
- var1[var2] = (byte)var4;
- int var5 = 1;
-
- while(this.field_0 >= 0) {
- --var3;
- if (var3 <= 0) {
- break;
- }
-
- var1[var2 + var5] = this.buffer[this.out++];
- ++var5;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
- }
-
- return var5;
- }
- }
- }
-
- public synchronized int available() throws IOException {
- if (this.field_0 < 0) {
- return 0;
- } else if (this.field_0 == this.out) {
- return this.buffer.length;
- } else {
- return this.field_0 > this.out ? this.field_0 - this.out : this.field_0 + this.buffer.length - this.out;
- }
- }
-
- public void close() throws IOException {
- this.field_0 = -1;
- this.closed = true;
- }
- }
-